#ifndef _MY_MQTT_H
#define _MY_MQTT_H

#include <stdlib.h>
#include "mqtt_client.h"

#include "cleaner.h"
#include "cJSON.h"


//////////华为云平台///////////
#define HOST "121.36.42.100"
#define PORT 1883
#define CLIENT_ID "600bb47ab86d7b02dbb3f9ad_84cca8483d0a_0_0_2021031608"
#define USER_NAME "600bb47ab86d7b02dbb3f9ad_84cca8483d0a"
#define PASSWORD  "6864296969bbd2fef381a84809bd0ac40bd61a7ea2bc3a4723ee19f34a81b917"

//////////属性上报///////////
#define DEVICE_ID "600bb47ab86d7b02dbb3f9ad_84cca8483d0a"
#define REPORT_TOPIC "$oc/devices/600bb47ab86d7b02dbb3f9ad_84cca8483d0a/sys/properties/report"

//////////命令下发//////////

#define RESQUESTID_LEN 36  //华为云的requestid是在最后的，有36位长度

//平台下行
#define ISSUED_TOPIC "$oc/devices/600bb47ab86d7b02dbb3f9ad_84cca8483d0a/sys/commands/#"
//设备响应
#define RESPON_TOPIC "$oc/devices/600bb47ab86d7b02dbb3f9ad_84cca8483d0a/sys/commands/response/600bb47ab86d7b02dbb3f9ad_84cca8483d0a"









//
#define SETPLACE_RESULT 100 //约定100作为设置工作地点的响应参数




//内部调用，应该用static
void mqtt_data_handle(esp_mqtt_client_handle_t client, char*s);

void publish_report_property(esp_mqtt_client_handle_t client, cleaner *cleanerP);

void uartdata_handle(esp_mqtt_client_handle_t client, uint8_t * receivebuffer);

void publish_respond_time_command(esp_mqtt_client_handle_t client, uint16_t time);
void publish_respond_batval_command(esp_mqtt_client_handle_t client, uint8_t val);
void publish_respond_onoff_command(esp_mqtt_client_handle_t client, uint8_t order);
void publish_respond_setplace_command(esp_mqtt_client_handle_t client, uint8_t result);

uint16_t settime_comm_handle(cJSON *jsParas);
uint8_t querytime_comm_handle(void);
uint8_t onoff_comm_handle(cJSON *jsParas);
uint8_t setplace_comm_handle(esp_mqtt_client_handle_t client, cJSON *jsParas);
uint8_t querybatval_comm_handle(void);
uint8_t charge_comm_handle(void);

//
int findRequestIdIndex(char* str, char startChar);
void getRequestId(const char* srcdata, char* desdata);
void getRespondTopic(char* respondtopic, const char* reqid);


//外部调用
void mqtt_start(void);
void mqtt_reconnect(void);


#endif  /*_MY_MQTT_H*/